<div class="layui-fluid layui-anim febs-anim" id="febs-teacherProject" lay-title="打卡">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">

                    <form class="layui-form layui-table-form" enctype="multipart/form-data" id="user-add-form"
                          lay-filter="teacherProject-table-form" style="width: 600px">
                        <div class="layui-form-item" >
                            <label class="layui-label" >上次打卡时间：</label>
                            <div class="layui-input-block">
                                <div class="layui-btn layui-btn-radius layui-btn-success layui-btn-lg" th:text="${time}"></div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">当前位置</label>
                            <div class="layui-input-block">
                                <input type="text" name="address" readonly lay-verify="address" id="address" autocomplete="off"
                                       placeholder="获取当前位置" class="layui-input">
                                <input type="hidden" name="lat" id="lan">
                                <input type="hidden" name="lon" id="lon">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">签到类型</label>
                            <div class="layui-input-block">
                                <select name="type" lay-verify="required" lay-filter="types">
                                    <option value="">请选择签到类型</option>
                                    <!-- <option value="1" selected="">上班</option>-->
                                    <option value="1">上课</option>
                                    <option value="0">下课</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea placeholder="请输入打卡备注" name="description" class="layui-textarea"></textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">上传照片</label>
                            <div class="layui-upload-drag" id="test10">
                                <i class="layui-icon"></i>
                                <p>点击上传，或将文件拖拽到此处</p>
                                <div class="layui-hide" id="uploadDemoView">
                                    <hr>
                                    <img src="" alt="上传成功后渲染" style="max-width: 196px">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item ">
                            <button class="layui-btn" lay-submit="" lay-filter="user-add-form-submit" id="submit">提交
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script data-th-inline="javascript">
    layui.use(['jquery', 'laydate', 'form', 'upload'], function () {
        var $ = layui.jquery,
            element = layui.element,
            form = layui.form,
            $view = $('#febs-teacherProject'),
            upload = layui.upload;
        form.render();


        $(function () {
            var latlon = null;
            //ajax获取用户所在经纬度
            $.ajax({
                url: "http://api.map.baidu.com/location/ip?ak=8Av7sglg8pdmku8Q5CGUdVLgtE1yLX9f&coor=bd09ll",
                type: "POST",
                dataType: "jsonp",
                jsonp: "callback", //Jquery生成验证参数的名称
                processData: false,
                success: function (data) {
                    latlon = data.content.point.y + "," + data.content.point.x;
                    $("#lan").val(data.content.point.y);
                    $("#lon").val(data.content.point.x);
                    //ajax根据经纬度获取省市区
                    $.ajax({
                        type: "POST",
                        dataType: "jsonp",
                        url: 'http://api.map.baidu.com/geocoder/v2/?ak=C93b5178d7a8ebdb830b9b557abce78b&callback=renderReverse&location=' + latlon + '&output=json&pois=0',
                        success: function (json) {
                            if (json.status == 0) {
                                console.log(json);
                                //定位到区
                                // var add = json.result.addressComponent.province + "-" + json.result.addressComponent.city + "-" + json.result.addressComponent.district
                                //定位到城市
                                var add = json.result.addressComponent.province + "-" + json.result.addressComponent.city;
                                console.log(add);
                                // alert(json.result.addressComponent.province+"-"+json.result.addressComponent.city+"-"+json.result.addressComponent.district)
                                $("#address").val(add);
                            }
                        }
                    });
                }
            });
        })


        //拖拽上传
        upload.render({
            elem: '#test10',
            // url: ctx + 'scan/face/register', //改成您自己的上传接口
            accept: "images",
            acceptMime: 'image/*',//打开文件选择框时,只显示图片文件
            auto: false,  //是否选完文件后自动上传。默认值：true
            // bindAction: '#sub',
            choose: function (obj) {
                obj.preview(function (index, file, result) {
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', result);
                })
            },
            done: function (res) {
                layer.msg('上传成功');
                console.log(res)
            }
        });


        form.on('submit(user-add-form-submit)', function (data) {
            var formData = new FormData(document.getElementById("user-add-form"));
            $.ajax({
                url: ctx + 'attendance/add',
                data: formData,
                type: 'post',
                dataType: 'json',
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.message, {
                            icon: 6,
                            time: 3000
                        }, function () {
                            layer.closeAll();
                            window.location.reload();
                        });
                    } else {
                        layer.msg('操作失败,请重新上传', {
                            icon: 5,
                            time: 1000
                        });
                    }
                },
                error: function (data) {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 1000
                    });
                }
            });

            /* febs.post(ctx + 'course/add', data.field, function () {
                 layer.closeAll();
                 $('#febs-user').find('#query').click();
             });*/
            return false;
        });

    })
</script>






